package com.wyw.log.learning.custom_exception;

import lombok.Data;

/**
 * @Title   用户性能优化的自定义异常
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2024/3/28 17:56
 * Update History:
 * Author        Time            Content
 */
public class OptimizeException {

    @Data
    public static class CustomException extends RuntimeException {
        private String key;
        private String message;

        public CustomException(String key, String message) {
            super(String.format("(%s)-[%s]", key , message));
            this.key = key;
            this.message = message;
        }

        @Override
        public Throwable fillInStackTrace() {
            return this;
        }

        @Override
        public String toString() {
            return String.format("(%s)-[%s]", key , message);
        }

    }

    private static void fun(String name) {
        if (!"wyw".equals(name)) {
            throw new CustomException("OptimizeException.fun.35", "name is not wyw...");
        }
    }

    public static void main(String[] args) {

        fun("wywywwy");
    }
}
